package com.buffer.springai.controller;

import com.buffer.springai.config.NacosConfig;
import com.buffer.springai.service.SpringAIStreamService;
import com.buffer.springai.service.SpringAIUnStreamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/ai")
public class SpringAIController {
    
    @Resource
    private NacosConfig nacosConfig;

    @Autowired
    private SpringAIStreamService springAIStreamService;

    @Autowired
    private SpringAIUnStreamService springAIUnStreamService;


    @RequestMapping("/config")
    public String config() {
        String apiKey = nacosConfig.getApiKey();
        System.out.println("api-key from NacosConfig: '" + apiKey + "'");
        return "NacosConfig: '" + apiKey + "'";
    }
    
    @RequestMapping("/askAi")
    public String askAi(@RequestParam String content) {

        return springAIUnStreamService.askAIWithoutStream(content);
    }
    @RequestMapping("/askAi1")
    public String askAi1(@RequestParam String content) {

        return springAIStreamService.askAIWithStream(content);
    }
}